<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            //获取当前页的input框
            var currentPage = $("#currentPage");
            //设置总游记数量
            var pages = 1;
            //设置用于存储所有游记的数组
            var travelData = [];
            //封装成一个query方法
            function query() {
                //获取当前页的值
                var currentPageValue = currentPage.val();
                //获取当前页的容量的input框
                var pageSize = $("#pageSize").val();
                //获取游记列表
                $.get("/users/" + user.id + "/travels", {
                    currentPage: currentPageValue,
                    pageSize: pageSize
                }, function (data) {
                    //往数组数据中存储数据(第二个拼接到第一个之后)
                    $.merge(travelData, data.list);
                    //渲染数据
                    $(".travels").renderValues({list: travelData});
                    //给a链接绑定事件
                    $("a[data-url]").click(function () {
                        var url = $(this).data("url");
                        var id = $(this).data("id");
                        window.location.href = url + id;
                    })
                    //将当前页加一
                    currentPage.val(parseInt(currentPageValue) + 1);
                    //设置总页数的值
                    pages = data.pages;
                })
            }

            //页面加载完毕后执行一次
            query();
            //增加一个滚动事件
            $(window).scroll(function () {
                //页面的高度加上卷上去的高度大于等于整个文档的高度
                if ($(document).scrollTop() + $(window).height() + 1 >= $(document).height()) {
                    //获取当前页的值
                    var currentPageValue = currentPage.val();
                    //判断是否是最后一页
                    if (currentPageValue <= pages) {
                        query();
                    } else {//提示用户已到底
                        $(document).dialog({
                            type: "notice",
                            infoText: "已经到底了",
                            autoClose: 1000
                        })
                    }

                }
            })
        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<input type="hidden" id="currentPage" name="currentPage" value="1">
<input type="hidden" id="pageSize" name="pageSize" value="3">

<div class="container travels">
    <dl class="list" render-loop="list">
        <dd>
            <a href="javascript:;" data-url="/mine/editTravels.html?id=" render-attr="data-id=list.id">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"></h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
                    <span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>

</body>
</html>
